# -*- coding: utf-8 -*-

#(c)Jonathan & Gregoire (read __doc__ for more information)
#Copyright (C)%(author)s (%(date)s)
#
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

## @packagename view
# It is a collection of view object for implement MVC pattern design

import  os
from engine.view.Color import Color

## Documentation for Grid_view class
# Grid_view is a class between the Game class and the pattern Grid
class Grid_view (object) :
    ## The constructor
    # @param self: The pointer object
    def __init__(self):
        pass
    
        
    ## Public method where_put_card_on_x_axis
    # @param self The object pointer
    # @return: x
    def where_put_card_on_x_axis(self):
        print u"Choose a value for x axis"
        print u'x: ',
        try:
            x = input()
        except NameError:
            x = None
        except  SyntaxError:
            x = None
        return x
    
    ## Public method where_put_card_on_y_axis
    # @param self The object pointer
    # @return: y
    def where_put_card_on_y_axis(self):
        print u"Choose a value for y axis"
        print u'y: ',
        try:
            y = input()
        except NameError:
            y = None
        except  SyntaxError:
            y = None
        return y
    
    ## Public method where_put_card
    # @param self The object pointer
    # @return: x and y
    def where_put_card(self):
        print u"Choose coordinates for put card in the grid"
        x = self.where_put_card_on_x_axis()
        y = self.where_put_card_on_y_axis()
        return x,y
    
    ## Public method bad_x_value
    # @param self The object pointer
    # @param x: x axis
    def bad_x_value(self,x):
        color = Color()
        print u'You can\'t put a card in ',color.red(),x,color.end(),u'x axis!'
        print u'Try again\n\n'
    
    
    ## Public method bad_y_value
    # @param self The object pointer
    # @param y: y axis
    def bad_y_value(self,y):
        color = Color()
        print u'You can\'t put a card in ',color.red(),y,color.end(),u'y axis!'
        print u'Try again\n\n'
        
    ## Public method bad_coordinate
    # @param self The object pointer
    # @param x: x axis
    # @param y: y axis
    # @return: True    
    def bad_coordinate(self,x,y):
        color = Color()
        print u'They are already a card at ',color.red(),x,color.end(),u'x',color.red(),y,color.end()
        print u'Choose an another position'
        return True
    
    ## Public method bad_ccordinate
    # @param self The object pointer
    # @param x: x axis
    # @param y: y axis
    # @return: True    
    def bad_position(self,x,y):
        color = Color()
        print u'You can not put this card at ',color.red(),x,color.end(),u'x',color.red(),y,color.end()
        print u'Choose an another position or try to rotate the card before put here.'
        return True
    
    ## Private method __beautiful_print
    # @param self The object pointer
    # @param text: The text who need be colored
    # @return: color_text A colored text
    def __beautiful_print(self,text):
        color = Color()
        if text == u'F':
            color_text = color.green()+text+color.end()
        elif text == u'R' or text == u'S':
            color_text = color.blue()+text+color.end()
        elif text == u'P':
            color_text = color.yellow()+text+color.end()
        else:
            color_text = text
        return color_text
    
    def show(self,grid):
        i = 0
        j = 0
        os.system("clear")
        print ' ',
        for i in range(10):
            print u' ',u' ',i,u' ',
        for raw in grid:
            print u'\n',u'_'*85,u'\n',u' ',u'|',
            for card in raw:
                print self.__beautiful_print(card.get_border_up_left()),self.__beautiful_print(card.get_border_up()),self.__beautiful_print(card.get_border_up_right()),u'|',
            print u'\n',j,u'|',
            for card in raw:
                print self.__beautiful_print(card.get_border_left()),self.__beautiful_print(card.get_middle()),self.__beautiful_print(card.get_border_right()),u'|',
            print j,u'\n',u' ',u'|',
            for card in raw:
                print self.__beautiful_print(card.get_border_down_left()),self.__beautiful_print(card.get_border_down()),self.__beautiful_print(card.get_border_down_right()),u'|',
            j += 1
        print u'\n',u'_'*85
        print ' ',
        for i in range(10):
            print u' ',u' ',i,u' ',
        print '\n'
        
        # Public method are_you_sure
    # @summary: it is the main game menu
    # @param x: x position on axis
    # @param y: y position on axis
    # @return answer
    def are_you_sure(self,x,y):
        color = Color()
        print u'Did you want put this card in position: ',color.blue(),x,color.end(),u'x',color.blue(),y,color.end(),color.green(),u' [y]es',color.end(),u' or ',color.red(),u'[n]o',color.end(),u'?'
        print u'Your choice: ',
        answer = raw_input()
        return answer
    
    ## Public method choice_not_understand
    # @param self: The object pointer
    # @param choice: the choice enter by the player
    def choice_not_understand(self,choice):
        print u'Sorry, your choice: ',choice,u' didn\'t have understood'
        print u'Please enter gain your choice, thanks'